package com.framework.core.utils;

import java.util.HashMap;
import java.util.Map;

import com.framework.core.domain.Control;
import com.framework.core.myexception.NoSuchComponentException;

//requestmapping请求匹配
public class RequestMappingUtils {

	private static RequestMappingUtils mappingUtils;

	private Map<String, Control> controller = new HashMap<>();

	private RequestMappingUtils() {

	}

	public synchronized static RequestMappingUtils getInstance() {

		if (null == mappingUtils) {
			// synchronized (RequestMappingUtils.class) {
			mappingUtils = new RequestMappingUtils();
			// }

		}
		return mappingUtils;

	}

	// 从controllerBeans集合取controller
	public Object getControllerByName(String name) throws NoSuchComponentException {

		if (controller.containsKey(name)) {
			return controller.get(name);
		} else {
			System.err.println("不存在：---" + name + "----controller！");
			throw new NoSuchComponentException("不存在：---" + name + "----requestMapping！");
		}

	}

	public Map<String, Control> getController() {
		return controller;
	}

	public void setController(Map<String, Control> controller) {
		this.controller = controller;
	}

}
